/** 
 * File-Name:AppAction.java
 *
 * Created on 2011-6-3 下午04:43:58
 * 
 * @author: Neo (neolimeng@gmail.com)
 * Software Engineering Institute, Peking University, China
 * 
 * Copyright (c) 2009, Peking University
 * 
 *
 */
package site.web;

import java.util.LinkedList;
import java.util.List;

import neoutil.CommonAction;

import org.apache.log4j.Logger;

import site.entity.Article;
import site.entity.Category;
import site.entity.Resource;
import site.entity.User;
import site.service.ArticleRepository;
import site.service.ResourceRepository;

/**
 * Description:
 * 
 * @author: Neo (neolimeng@gmail.com) Software Engineering Institute, Peking
 *          University, China
 * @version 1.0 2011-6-3 下午04:43:58
 */
public class AppAction extends CommonAction {

	private static final long serialVersionUID = 8149446973529460548L;
	private static Logger log = Logger.getLogger(AppAction.class);
	private List<Article> latestNotices;
	private List<Article> articles01;
	private List<Article> articles02;
	private List<Article> articles03;
	private List<Article> articles04;
	private List<Article> articles05;

	private Article article01;
	private Article article02;
	private Article article03;
	private Article article04;
	private Article article05;

	private List<Resource> resources01;
	private List<Resource> resources02;
	private List<Resource> resources03;
	private List<Resource> resources04;
	private List<Resource> resources05;

	public String toHome() {
		try {
			/**
			 * 首页最新“通知公告”
			 */
			ArticleRepository articleRepository = getArticleRepository();
			ResourceRepository resourceRepository = getResourceRepository();

			latestNotices = articleRepository.getLatestArticlesByCid(Category.TZGG, 5);
			articles01 = articleRepository.getLatestArticlesByCid(Category.ZYZJ, 5);

			article01 = articleRepository.getLatestArticleByCid(Category.ZXDT);
			article02 = articleRepository.getLatestArticleByCid(Category.SJFC);
			article03 = articleRepository.getLatestArticleByCid(Category.SJZX);

			int resourceCount = 7;
			resources01 = resourceRepository.getLatestResourcesByCid(Category.YLK, resourceCount);
			resources02 = resourceRepository.getLatestResourcesByCid(Category.TXK, resourceCount);
			resources03 = resourceRepository.getLatestResourcesByCid(Category.GYK, resourceCount);
			resources04 = resourceRepository.getLatestResourcesByCid(Category.JCK, resourceCount);
			resources05 = resourceRepository.getLatestResourcesByCid(Category.XSYZC, resourceCount);

			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return INPUT;
		}
	}

	public String toManageHome() {
		try {
			User user = (User) getSessionObject("loginUser");
			if (user == null) {
				log.error("用户未登录！");
				return RELOGIN;
			} else {
				return SUCCESS;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return INPUT;
		}
	}

	public String to() {
		return SUCCESS;
	}

	// Getters and Setters
	public List<Article> getLatestNotices() {
		return latestNotices;
	}

	public void setLatestNotices(List<Article> latestNotices) {
		this.latestNotices = latestNotices;
	}

	public List<Article> getArticles01() {
		return articles01;
	}

	public void setArticles01(List<Article> articles01) {
		this.articles01 = articles01;
	}

	public List<Article> getArticles02() {
		return articles02;
	}

	public void setArticles02(List<Article> articles02) {
		this.articles02 = articles02;
	}

	public List<Article> getArticles03() {
		return articles03;
	}

	public void setArticles03(List<Article> articles03) {
		this.articles03 = articles03;
	}

	public List<Article> getArticles04() {
		return articles04;
	}

	public void setArticles04(List<Article> articles04) {
		this.articles04 = articles04;
	}

	public List<Article> getArticles05() {
		return articles05;
	}

	public void setArticles05(List<Article> articles05) {
		this.articles05 = articles05;
	}

	public Article getArticle01() {
		return article01;
	}

	public void setArticle01(Article article01) {
		this.article01 = article01;
	}

	public Article getArticle02() {
		return article02;
	}

	public void setArticle02(Article article02) {
		this.article02 = article02;
	}

	public Article getArticle03() {
		return article03;
	}

	public void setArticle03(Article article03) {
		this.article03 = article03;
	}

	public Article getArticle04() {
		return article04;
	}

	public void setArticle04(Article article04) {
		this.article04 = article04;
	}

	public Article getArticle05() {
		return article05;
	}

	public void setArticle05(Article article05) {
		this.article05 = article05;
	}

	public List<Resource> getResources01() {
		return resources01;
	}

	public void setResources01(List<Resource> resources01) {
		this.resources01 = resources01;
	}

	public List<Resource> getResources02() {
		return resources02;
	}

	public void setResources02(List<Resource> resources02) {
		this.resources02 = resources02;
	}

	public List<Resource> getResources03() {
		return resources03;
	}

	public void setResources03(List<Resource> resources03) {
		this.resources03 = resources03;
	}

	public List<Resource> getResources04() {
		return resources04;
	}

	public void setResources04(List<Resource> resources04) {
		this.resources04 = resources04;
	}

	public List<Resource> getResources05() {
		return resources05;
	}

	public void setResources05(List<Resource> resources05) {
		this.resources05 = resources05;
	}
}
